<?php

define('IN_PHPBB', true);
$phpbb_root_path = '../';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

unset($dbpasswd);

function json_safe_encode($var)
{
   return json_encode(json_fix_cyr($var));
}

function json_fix_cyr($var)
{
   if (is_array($var)) {
       $new = array();
       foreach ($var as $k => $v) {
           $new[json_fix_cyr($k)] = json_fix_cyr($v);
       }
       $var = $new;
   } elseif (is_object($var)) {
       $vars = get_object_vars($var);
       foreach ($vars as $m => $v) {
           $var->$m = json_fix_cyr($v);
       }
   } elseif (is_string($var)) {
       $var = iconv('cp1251', 'utf-8', $var);
   }
   return $var;
}

$TimeStamp = NULL;
$Calendar_Event = array();

if(isset($HTTP_GET_VARS["date"]) && $HTTP_GET_VARS["date"] != null) {
    $TimeStamp = $HTTP_GET_VARS["date"];
}

$Query = "SELECT Text, Title FROM ".CALENDAR_EVENT_TABLE." WHERE date='$TimeStamp'";

if(!$result = $db->sql_query($Query)){
    message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $Query);
};

while ($row = $db->sql_fetchrow($result)){
    
    $Calendar_Event[] = array("Title" =>iconv('cp1251', 'utf-8', $row['Title']), 
        "Text" => iconv('cp1251', 'utf-8', $row["Text"])
        );
    
};

//print_r($Calendar_Event);
$db->sql_freeresult($result);


foreach ($Calendar_Event as $key => &$value)
{
    //print_r($value);
 
}

?>
